/*
*********************************
	PlovR Game Engine
*********************************

	By Julian Williams
	June 11, 2010
**********************************

	Description:

		Camera used to scroll
	through the game's envirnment
***********************************
*/
#include <SFML/Graphics.hpp>

#include "app.h"
#include "levels.h"

#include "Camera.h"
#include "Parallax.h"



Camera Cam;



Camera::Camera(void)
{
	//camera_pos.x = 0;
	//camera_pos.y = 0;
}

//Setter for Camera Vector
//Grab Camera position;
void Camera::Set_Camera( sf::Vector2f new_position ) 
{	
	//X coordinate
	//Make sure the Camera isn't greater than map size
	Set_CameraX(new_position.x);
	
	//Y Coordinate
	Set_CameraY(new_position.y);

}//EoF



//Set X camera
void Camera::Set_CameraX( float new_x ) 
{


	if(new_x > Map.Get_PixelSize().x - (App::getInstance().Get_RenderWindow()->GetWidth() + Map.Get_TileSize().x))
	{
		new_x = Map.Get_PixelSize().x - (App::getInstance().Get_RenderWindow()->GetWidth() + Map.Get_TileSize().x);
	}

	//make sure camera isn't less than camera size
	if(new_x < Map.Get_TileSize().x)
	{
		new_x = Map.Get_TileSize().x;
	}

	//Set final camera position
	SetX( new_x );
	//scroll_pos.x = new_x;

}//EoF



//Set Y Camera
void Camera::Set_CameraY( float new_y )
{

	
	if(new_y > (Map.Get_PixelSize().y) - (App::getInstance().Get_RenderWindow()->GetHeight() + Map.Get_TileSize().y))
	{
		new_y = Map.Get_PixelSize().y - (App::getInstance().Get_RenderWindow()->GetHeight() + Map.Get_TileSize().y);
	}

	//make sure camera isn't less than camera size
	if(new_y < Map.Get_TileSize().y)
	{
		new_y = Map.Get_TileSize().y;
	}

	//Set CameraY position
	SetY( new_y );
	//scroll_pos.y = new_y;

}//EoF



//Move Camera
void  Camera::Move_Camera(sf::Vector2f new_position)
{
	//sf::Vector2f temp;
	//temp.x = GetPosition().x + new_position.x;
	//temp.y = GetPosition().y + new_position.y;

	//Set_Camera(temp);

	Move_CameraX( new_position.x );
	Move_CameraY( new_position.y );
}

void  Camera::Move_CameraX(float new_x)
{
	Set_CameraX(GetPosition().x + new_x);
	//for parallax Background
	scroll_pos.x = new_x;
	//cout << scroll_pos.x << endl;

	Parallax::Set_ScrollX( new_x );
}

void  Camera::Move_CameraY(float new_y)
{
	Set_CameraY(GetPosition().y + new_y);
	//for parallax background
	scroll_pos.y = new_y;
	//cout << scroll_pos.y << endl;

	Parallax::Set_ScrollY( new_y );

}



//Check to see if we can scroll
bool  Camera::canScroll_Left()
{
	if(GetPosition().x > Map.Get_TileSize().x)
	{
		return true;
	}

	return false;
}//EoF

bool  Camera::canScroll_Right()
{
	if(GetPosition().x < Map.Get_PixelSize().x - (App::getInstance().Get_RenderWindow()->GetWidth() + Map.Get_TileSize().x))
	{
		return true;
	}
	
	return false;
}//EoF

bool  Camera::canScroll_Up()
{
	if(GetPosition().y > Map.Get_TileSize().y)
	{
		return true;
	}

	return false;
}//EoF

bool  Camera::canScroll_Down()
{
	if(GetPosition().y < Map.Get_PixelSize().y - (App::getInstance().Get_RenderWindow()->GetHeight() + Map.Get_TileSize().y))
	{
		return true;
	}

	return false;
}//EoF